package com.test.myrxjava;

import androidx.appcompat.app.AppCompatActivity;



import android.os.Bundle;
import android.util.Log;

import com.test.myrxjava.core.Emitter;
import com.test.myrxjava.core.Observable;
import com.test.myrxjava.core.ObservableOnSubscribe;
import com.test.myrxjava.core.Observer;
import com.test.myrxjava.core.map.Function;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivityTag";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG, "onCreate: ");
        Observable.create(new ObservableOnSubscribe<Object>() {
            @Override
            public void subscribe(Emitter<Object> emitter) {
                Log.i(TAG, "subscribe: ");
                emitter.onNext("aaaa");
                emitter.onError(new Throwable());
                emitter.onComplete();
            }
        })
                .map(new Function<Object,Object >() {

                    @Override
                    public  Object apply(Object o) {
                        return "处理后:" + o;
                    }
                })
                .subscribe(new Observer<Object>() {

            @Override
            public void onSubscribe() {
                Log.i(TAG, "onSubscribe: ");
            }

            @Override
            public void onNext(Object o) {
                Log.i(TAG, "onNext: " +o );
            }

            @Override
            public void onComplete() {
                Log.i(TAG, "onComplete: ");
            }

            @Override
            public void onError(Throwable throwable) {
                Log.i(TAG, "onError: ");
            }
        });
    }
}